package com.dhcc.bpm.modules.sandbox.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.sandbox.entity.TestDictData;
import com.dhcc.bpm.modules.sandbox.service.ITestDictDataService;
import com.dhcc.bpm.modules.sandbox.vo.TestDictDataVO;
import com.dhcc.bpm.modules.system.service.ISerialNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName TestDictDataController
 * @Description 测试数据类型表 控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping("bpm-sandbox/testdictdata")
@Api(value = "测试数据类型表", tags = "测试数据类型表接口")
public class TestDictDataController extends BladeController {

	private ITestDictDataService testDictDataService;
	private ISerialNumberService serialNumberService;

	/**
	 * @Description 详情
	 * @Author sjm
	 * @Date 21:35 2020/2/21 0021
	 * @param testDictData
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.sandbox.entity.TestDictData>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入testDictData")
	@ApiLog("测试数据类型表详情")
	@Log(title = "测试数据类型表详情", businessType = BusinessType.SELECT)
	public R<TestDictData> detail(TestDictData testDictData) {
		TestDictData detail = testDictDataService.getOne(Condition.getQueryWrapper(testDictData));
		return R.data(detail);
	}

	/**
	 * @Description  分页 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param testDictData
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.sandbox.entity.TestDictData>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入testDictData")
	@ApiLog("分页查询测试数据类型表")
	@Log(title = "测试数据类型表", businessType = BusinessType.SELECT)
	public R<IPage<TestDictData>> list(@ApiIgnore @RequestParam Map<String, Object> testDictData, Query query) {
		IPage<TestDictData> pages = testDictDataService.page(Condition.getPage(query), Condition.getQueryWrapper(testDictData, TestDictData.class));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param testDictData
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.sandbox.vo.TestDictDataVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入testDictData")
	@ApiLog("分页查询测试数据类型表")
	@Log(title = "测试数据类型表", businessType = BusinessType.SELECT)
	public R<IPage<TestDictDataVO>> page(TestDictDataVO testDictData, Query query) {
		IPage<TestDictDataVO> pages = testDictDataService.selectTestDictDataPage(Condition.getPage(query), testDictData);
		return R.data(pages);
	}

	/**
	 * @Description 新增 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param testDictData
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入testDictData")
	@ApiLog("测试数据类型新增")
	@Log(title = "测试数据类型新增", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody TestDictData testDictData) {
		return R.status(testDictDataService.save(testDictData));
	}

	/**
	 * @Description 修改 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param testDictData
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入testDictData")
	@ApiLog("测试数据类型修改")
	@Log(title = "测试数据类型修改", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody TestDictData testDictData) {
		return R.status(testDictDataService.updateById(testDictData));
	}

	/**
	 * @Description 新增或修改 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param testDictData
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入testDictData")
	@ApiLog("测试数据类型修改")
	@Log(title = "测试数据类型修改", businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody TestDictData testDictData) {
		if(testDictData.getId()==null){
			String code = serialNumberService.generateSerialNumberByModelCode("opc_test_dict_data");
			testDictData.setTestCode(code);
		}
		return R.status(testDictDataService.saveOrUpdate(testDictData));
	}

	
	/**
	 * @Description 删除 测试数据类型表
	 * @Author sjm
	 * @Date 21:36 2020/2/21 0021
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	@ApiLog("测试数据类型删除")
	@Log(title = "测试数据类型删除", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(testDictDataService.deleteLogic(Func.toLongList(ids)));
	}

	
}
